import { View } from "../../../mvc/core/View";
import { IPetHirePanel } from "./IPetHirePanel";
import { Language } from "../../../../extend/language/Language";
import { PageTool } from "../../../common/global/PageTool";
import { ObjCreate } from "../common/ObjCreate";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { ImagesConst } from "../../resource/ImagesConst";
import { TilePanel } from "../equipment/TilePanel";
import { PetHireApplyRenderer } from "./PetHireApplyRenderer";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { PageSelecter } from "../common/pageSelect/PageSelecter";
import { SPlayerPetRentLog } from "../../../../Message/Game/SPlayerPetRentLog";
import { MsgManager } from "../../manager/MsgManager";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { PetHireEventName } from "./PetHireEventName";
import { EPrictUnit } from "../../../../Message/Public/EPrictUnit";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { DateParser } from "../../../common/tools/DateParser";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { EffectManager } from "../../manager/EffectManager";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { GTextInput } from "../../../../com/mui/controls/GTextInput";
import { GButton } from "../../../../com/mui/controls/GButton";
import { _logString } from "../../../../this/_logString";
type int = number;
//class PetHireApplyPanel
    
    export  class PetHireApplyPanel extends View implements IPetHirePanel
    {
        constructor()
        {
            super();
            this._tip = Language.getString(54323);
            this._pageTool = new PageTool([], 3);
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            this._topPanel = new Object /* flash.display.Sprite */();
            this.addChild(this._topPanel);
            ObjCreate.createTextField(Language.getString(54324), 5, 5, 60, 20, this._topPanel, GlobalStyle.textFormat2);
            ObjCreate.createBitmap(ImagesConst.Tongqian_small, 63, 6, this._topPanel);
            this._coinInput = ObjCreate.createGTextInput(80, 5, 65, 20, this._topPanel);
            this._coinInput.text = "0";
            this._coinInput.editable = false;
            ObjCreate.createBitmap(ImagesConst.Yuanbao_small, 150, 6, this._topPanel);
            this._goldInput = ObjCreate.createGTextInput(170, 5, 65, 20, this._topPanel);
            this._goldInput.text = "0";
            this._goldInput.editable = false;
            this._getBtn = ObjCreate.createGButton(Language.getString(54325), 245, 5, 60, 24, this._topPanel);
            this._getBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onGetBtnClickHandler);
            this._recordBtn = ObjCreate.createGButton(Language.getString(54326), 515, 5, 70, 24, this._topPanel);
            this._recordBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onRecordBtnClickHandler);
            this._applyList = new TilePanel();
            this._applyList.setStyle("cellRenderer", PetHireApplyRenderer);
            this._applyList.columnWidth = 590;
            this._applyList.rowHeight = 95;
            this._applyList.setSize(595, 285);
            this._applyList.move(0, 35);
            this.addChild(this._applyList);
            ObjCreate.createTextField(Language.getString(54544), 20, 325, 220, 20, this, new GTextFormat(FontUtil.songtiName, 12, 15788607));
            this._applyedNumTxt = ObjCreate.createTextField("0/2", 70, 325, 220, 20, this, new GTextFormat(FontUtil.songtiName, 12, 15788607));
            this._pageBar = ObjCreate.createPageSelecter(230, 325, this);
            this._pageBar.mode = PageSelecter.CompleteMode;
            this._pageBar.addEventListener(flash.events.Event.CHANGE, this.onPageChangeHandler);
            this._tipTxt = ObjCreate.createTextField("", 0, 145, 600, 50, this, new GTextFormat(FontUtil.songtiName, 16, 15788607));
            this._tipTxt.visible = false;
            this._tipTxt.multiline = true;
            this._tipTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._tipTxt.htmlText = "<textFormat leading=\'5\'>" + this._tip + "</textFormat>";
            return;
        }

        public updateDataProvider(arg1: Array<any>, arg2: int, arg3: int=1): void
        {
            this._pageTool.array = arg1;
            this._pageBar.currentPage = 1;
            this._pageBar.maxPage = this._pageTool.pagesCount;
            this.onPageChangeHandler(null);
            if (arg1.length > 0) 
            {
                this._tipTxt.visible = false;
            }
            else 
            {
                this._tipTxt.visible = true;
            }
            return;
        }

        public updateMoney(arg1: int, arg2: int): void
        {
            this._totalCoin = arg1;
            this._totalGold = arg2;
            this._coinInput.text = arg1.toString();
            this._goldInput.text = arg2.toString();
            return;
        }

        public updateRecord(arg1: SPlayerPetRentLog): void
        {
            if (arg1) 
            {
                this._logString = this.getLogString(arg1);
            }
            return;
        }

        public setDefault(): void
        {
            return;
        }

        /* internal  */onGetBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._totalCoin == 0 && this._totalGold == 0) 
            {
                MsgManager.showRollTipsMsg(Language.getString(54327));
                return;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.PetHireGetMoney));
            return;
        }

        /* internal  */onRecordBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=null;
            Dispatcher.dispatchEvent(new DataEvent(PetHireEventName.OpenInfoPanel, {"content": _logString, "isHelp": false}));
            return;
        }

        /* internal  */getLogString(arg1: SPlayerPetRentLog): string
        {
            var loc2=0;
            var loc3=0;
            var loc4=null;
            var loc5=0;
            var loc6=null;
            var loc7=null;
            var loc1="";
            if (arg1) 
            {
                var loc8=0;
                var loc9=arg1.petRentLogs;
                for(loc6 of loc9) 
                {
                    loc7 = "";
                    loc4 = (loc3 = loc6.unit) != EPrictUnit._EPriceUnitGold ? Language.getString(54329) : Language.getString(54328);
                    loc2 = loc6.price;
                    loc5 = loc2 - Math.ceil(loc2 * 0.05);
                    loc7 = (loc7 = (loc7 = (loc7 = loc7 + HTMLUtil.addColor(DateParser.parse(loc6.borrowTime, "[MM-dd hh: mm]"), "#e4ff00")) + (Language.getString(54330) + HTMLUtil.addColor(loc6.playerName, "#00e4ff"))) + (Language.getStringByParam(54331, loc6.price, loc4) + HTMLUtil.addColor(loc6.petName, "#f000ff"))) + Language.getStringByParam(54332, loc5, loc4);
                    loc1 = loc1 + loc7;
                }
                loc1 = HTMLUtil.addColor(loc1, "#B1efff");
            }
            return loc1;
        }

        /* internal  */onPageChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            this._cpage = this._pageBar.currentPage;
            this.updateByArray(this._pageTool.getByPageNo(this._cpage));
            return;
        }

        /* internal  */updateByArray(arg1: Array<any>): void
        {
            if (!this._dataP) 
            {
                this._dataP = new DataProvider();
            }
            this._dataP.removeAll();
            var loc1=0;
            while (loc1 < arg1.length) 
            {
                this._dataP.addItem(arg1[loc1]);
                ++loc1;
            }
            this._applyList.dataProvider = this._dataP;
            return;
        }

        public flashButton(): void
        {
            if (!(this._totalCoin == 0) || !(this._totalGold == 0)) 
            {
                if (this._flashTimer == null) 
                {
                    this._flashTimer = new Object /* flash.utils.Timer */(1000);
                    this._flashTimer.repeatCount = 5;
                }
                this._flashTimer.addEventListener(flash.events.TimerEvent.TIMER_COMPLETE, this.onFlashCompleteHandler);
                this._flashTimer.reset();
                this._flashTimer.start();
                EffectManager.glowFilterReg(this._getBtn, [FilterConst.uiBtnFilter]);
            }
            return;
        }

        /* internal  */onFlashCompleteHandler(arg1: Object /* flash.events.Event */): void
        {
            if (this._flashTimer) 
            {
                this._flashTimer.stop();
            }
            EffectManager.glowFilterUnReg(this._getBtn);
            return;
        }

        public updateApplyedNum(arg1: int): void
        {
            this._applyedNumTxt.text = arg1 + "/2";
            return;
        }

        /* internal */ /* var */_topPanel: Object /* flash.display.Sprite */;

        /* internal */ /* var */_coinInput: GTextInput;

        /* internal */ /* var */_goldInput: GTextInput;

        /* internal */ /* var */_getBtn: GButton;

        /* internal */ /* var */_recordBtn: GButton;

        /* internal */ /* var */_recordInput: GTextInput;

        /* internal */ /* var */_applyList: TilePanel;

        /* internal */ /* var */_applyedNumTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_pageBar: PageSelecter;

        /* internal */ /* var */_tipTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_tip: string;

        /* internal */ /* var */_pageTool: PageTool;

        /* internal */ /* var */_cpage: int=1;

        /* internal */ /* var */_dataP: DataProvider;

        /* internal */ /* var */_totalCoin: int;

        /* internal */ /* var */_totalGold: int;

        /* internal */ /* var */_flashTimer: Object /* flash.utils.Timer */;

        /* internal */ /* var */_logString: string="";
    }
